//页面载入时执行
window.onload=userInfo;

//js载入完成后执行代码
$(function(){
	
	
});
function register(){
	location.href="register.html";
}
//更新密码
function passClick(){
	$.ajax({
        url: "http://127.0.0.1:8080/user/updatePass",
        timeout: 30000,
        type: "get",
        dataType: "json",
        data:{oldPass:$("#oldPass").val(),user_id:$("#passId").val(),newPass:$("#newPass").val()},
        success: function (data) {
        	if(data.rtn==true){
        		$(".pass").val("");
        		alert("密码修改成功");
        	}else{
        		alert("原密码错误");
        	}
        }
	});
}

//更新个人信息
function updateInfo(){
	$.ajax({
        url: "http://127.0.0.1:8080/user/updateInfo",
        timeout: 30000,
        type: "get",
        dataType: "json",
        data:{user_name:$("#name").val(),address:$("#address").val(),phone:$("#phone").val(),user_id:$("#id").val()},
        success: function (data) {
        	alert("更新成功,请再次点击页面查看！");
        }
	});
	
}
//获取个人信息
function myPerson(){
	$.ajax({
        url: "http://127.0.0.1:8080/user/userInfo",
        timeout: 30000,
        type: "get",
        dataType: "json",
        success: function (data) {
        	$("#name").val(data.user_name);
        	$("#balance").val(data.balance+".00元");
        	$("#address").val(data.address);
        	$("#phone").val(data.phone);
        	$("#id").val(data.user_id);
        }
	});
}
//密码栏清空
function passworda(){
	$(".pass").val("");
}
//载入界面时显示用户基本信息
function userInfo(){
	$.ajax({
        url: "http://127.0.0.1:8080/user/userInfo",
        timeout: 30000,
        type: "get",
        dataType: "json",
        success: function (data) {
        	var html = "";
        	$("img").attr("src",data.headimgurl);
        	html=data.user_name;
			$("#username").html(html);
			$("#passId").val(data.user_id);
        }
	});
}